package com.jdd.modules.people.model;

import com.alibaba.fastjson.JSONObject;
import com.jdd.dao.entity.*;
import com.jdd.modules.device.entity.TDevice;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: LS
 * @Date: 2022 - 09 - 20 - 14:34
 * @Description: 项目树model类
 * @version: 1.0
 */
@Data
@NoArgsConstructor
public class TProjectTreeModel implements Serializable {
    private static final long serialVersionUID = 1L;
    /** 对应Tprojectg中的id字段,前端数据树中的key*/
    private String key;

    private String value;


    private String title;


    private boolean isLeaf;


    private List<TProjectTreeModel> children = new ArrayList<>();

    /**是否是区域(0为项目，1为区域，2为楼栋，3为单元，4为楼层,5为房屋,6为设备)*/
    private Integer isArea;


    private String id;


    private String parentId;

    private String areaName;

    private String name;

    /**插槽*/
    private JSONObject slots;


    //将TProject对象转换成TProjectTreeModel中的对象
    public TProjectTreeModel(TProject tProject){
        this.id = tProject.getId();
        this.key = tProject.getId();
        this.value = tProject.getId();
        this.title =tProject.getName();
        this.parentId = null;
        this.isArea = 0;
        this.slots = new JSONObject();
        this.slots.put("icon","project");
    }

    //将house对象转换成TProjectTreeModel中的对象
    public TProjectTreeModel(THouse tHouse){
        this.id = tHouse.getId();
        this.key = tHouse.getId();
        this.value = tHouse.getId();
        this.title =tHouse.getHouseName();
        this.parentId = null;
        this.isArea = 5;
        this.slots = new JSONObject();
        this.slots.put("icon","house");
    }
    //将TArea对象转换成TProjectTreeModel中的对象
    public TProjectTreeModel(TArea tArea){
        this.id = tArea.getId();
        this.key = tArea.getId();
        this.value = tArea.getId();
        this.title = tArea.getName();
        this.parentId = tArea.getParentId();
        this.isArea = 1;
        this.slots = new JSONObject();
        this.slots.put("icon","area");
    }

    public TProjectTreeModel(TDevice TDevice, TArea area){
        this.id = TDevice.getDeviceSn();
        this.key = TDevice.getDeviceSn();
        this.value = TDevice.getDeviceSn();
        this.title =TDevice.getDeviceAlias();
        this.parentId = area.getId();
        this.isArea = 6;
    }
    public TProjectTreeModel(TDevice TDevice,TBuilding building){
        this.id = TDevice.getDeviceSn();
        this.key = TDevice.getDeviceSn();
        this.value = TDevice.getDeviceSn();
        this.title =TDevice.getDeviceAlias();
        this.parentId = building.getId();
        this.isArea = 6;
    }
    public TProjectTreeModel(TDevice TDevice,TUnit tUnit){
        this.id = TDevice.getDeviceSn();
        this.key = TDevice.getDeviceSn();
        this.value = TDevice.getDeviceSn();
        this.title =TDevice.getDeviceAlias();
        this.parentId =  tUnit.getId();
        this.isArea = 6;
    }
    public TProjectTreeModel(TDevice TDevice,TFloor tFloor){
        this.id = TDevice.getDeviceSn();
        this.key = TDevice.getDeviceSn();
        this.value = TDevice.getDeviceSn();
        this.title =TDevice.getDeviceAlias();
        this.parentId =   tFloor.getId();
        this.isArea = 6;
    }

    public TProjectTreeModel(TDevice TDevice){
        this.id = TDevice.getDeviceSn();
        this.key = TDevice.getDeviceSn();
        this.value = TDevice.getDeviceSn();
        this.title =TDevice.getDeviceAlias();
        this.parentId =   TDevice.getHouseId();
        this.isArea = 6;
    }
    public TProjectTreeModel(TBuilding tBuilding) {
        this.id = tBuilding.getId();
        this.key =tBuilding.getId();
        this.value =tBuilding.getId();
        this.title =tBuilding.getBuildingName();
        this.parentId = tBuilding.getAreaId();
        this.isArea = 2;
        this.slots = new JSONObject();
        this.slots.put("icon","build");

    }

    public TProjectTreeModel(TUnit tUnit) {
        this.id = tUnit.getId();
        this.key = tUnit.getId();
        this.value = tUnit.getId();
        this.title = tUnit.getUnitName();
        this.parentId = tUnit.getBuildingId();
        this.isArea = 3;
        this.slots = new JSONObject();
        this.slots.put("icon","unit");

    }

    public TProjectTreeModel(TFloor tFloor) {
        this.id = tFloor.getId();
        this.key =tFloor.getId();
        this.value = tFloor.getId();
        this.title = tFloor.getFloorName();
        this.parentId = tFloor.getUnitId();
        this.isArea = 4;
        this.slots = new JSONObject();
        this.slots.put("icon","floor");
    }
}
